package com.ylfstu.set_;

import java.util.HashSet;
import java.util.Set;

public class HashSet_ {
    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        Set set = new HashSet();

        System.out.println(set.add("john"));
        System.out.println(set.add("lucy"));
        System.out.println(set.add("john"));
        System.out.println(set.add("jack"));
        System.out.println(set.add("Rose"));
        set.remove("john");
        System.out.println(set);

        set = new HashSet();
        set.add("lucy");
        set.add("lucy");
        set.add(new Dog("tom"));
        set.add(new Dog("tom"));

        set.add(new String("ylf"));//ok
        set.add(new String("ylf"));//加入不了

        System.out.println(set);
    }
}

class Dog { //定义了 Dog 类
    private String name;

    public Dog(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                '}';
    }
}
